<?php

	namespace Home\Controller;
	Use Think\Controller;

	class RegisterController extends Controller {

		public function emailCheck() {
			if (IS_GET) {
				$users = D('users');
				$condition['email'] = I('get.email');
				$result = $users->where($condition)->find();
				if ($result){
					$bool['hasemail'] = true;
				}
				else {
					$bool['hasemail'] = false;
				}
				$this->ajaxReturn($bool);
			}
		}

		public function mobileCheck() {
			if (IS_GET) {
				$users = D('users');
				$condition['mobile'] = I('get.mobile');
				$result = $users->where($condition)->find();
				if ($result){
					$bool['hasmobile'] = true;
				}
				else {
					$bool['hasmobile'] = false;
				}
				$this->ajaxReturn($bool);
			}
		}


		public function usernameCheck() {
			if (IS_GET) {
				$users = D('users');
				$condition['username'] = I('get.username');
				$result = $users->where($condition)->find();
				if ($result){
					$bool['hasusername'] = true;
				}
				else {
					$bool['hasusername'] = false;
				}
				$this->ajaxReturn($bool);
			}
		}


		public function register() {
			if (IS_POST) {
				$register = D('register');
				$data = $register->create();
				if ($data['email'] == "") {
					$data['email'] = '-';
				}
				if ($data['mobile'] == "") {
					$data['mobile'] = '0';
				}

				$result = $register->add($data);

				if ($result) {
					$this->success('注册成功', U('Blast/blast'), 2);
				}
				else {
					$this->error('注册失败');
				}
			}
		}
	}

?>
